package com.erpoa.config;


import com.google.common.cache.CacheBuilder;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @author chenjimin
 * @Title: CacheConfig
 * @ProjectName oaerp
 * @Description: TODO
 * @date 2020/10/1212:10
 */


@Configuration
@EnableCaching
public class CacheConfig {
    @Bean
    public CacheManager cacheManager() {
        GuavaCacheManager cacheManager = new GuavaCacheManager();
        cacheManager.setCacheBuilder(
                CacheBuilder.newBuilder().
                        expireAfterWrite(3600, TimeUnit.SECONDS).expireAfterAccess(3600, TimeUnit.SECONDS). //多长时间未读写后过期
                        maximumSize(1000)); //软件老王，6小时过期，最大1000条
        return cacheManager;
    }
}